﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using QXBook.Utils;
using QXBook.Service;
using QXBook.Model;
using System.Data;

namespace Web.ctrl
{
    public partial class Calendar : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //cal1.SelectionChanged += new EventHandler(cal1_SelectionChanged);
            CalendarItem1.MonthChanged += new QXBook.Controls.ServerControls.MonthChange(CalendarItem1_MonthChanged);

            if (!IsPostBack)
            {
                DateTime now = System.DateTime.Now;
                CalendarItem1.CurrentDate = now;
                if (CommonUtils.Get("Date").Length > 0)
                {
                    CalendarItem1.CurrentDate = Convert.ToDateTime(CommonUtils.Get("Date"));
                }
                TextBind();
                cal1.TodaysDate = now;
            }
        }

        void CalendarItem1_MonthChanged(object sender, EventArgs e)
        {
            TextBind();
        }

        public void TextBind()
        {
            PagerState ps = new PagerState();
            DateTime selectDate = CalendarItem1.CurrentDate;

            DataTable list = ServiceFactory.CreateInstance<VideoService>().GetDataByMonth(selectDate);

            cal1.DataSource = list;
            cal1.DataBind();
            //添加两行代码，使日历能随ddlYear.SelectedValue的变化而变化-cj.dai-1.20-
            //DateTime selectDate = DateTime.Parse(ddlYear.SelectedValue);//
            cal1.VisibleDate = selectDate;//
            //BindSelectDate();
            DateTime now = System.DateTime.Now;
            if (selectDate.ToString("MM/01/yyyy") == now.ToString("MM/01/yyyy"))
            {
                cal1.TodayDayStyle.CssClass = "showing"; //System.Drawing.Color.Yellow;
            }
            else
            {
                cal1.TodayDayStyle.BackColor = System.Drawing.Color.White;
            }

        }

        protected void cal1_SelectionChanged(object sender, EventArgs e)
        {
            //if (UserLoginAccount.IsCurrentUserHasThePermissions(EMS.Common.Enums.SysID.PWMS, SystemModuleList.PW_Calendar, ModulePermissions.Accessible))
            //{

            //    EMS.Common.Utility.Redirect("CalendarAdd.aspx" + Requests.Date.SetA(cal1.SelectedDate.ToString("MM/dd/yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo)));
            //}
            //else
            //{
            //    EMS.Common.Utility.Redirect("Calendar.aspx" + Requests.Date.SetA(CalendarItem1.SelectDate.ToString("MM/01/yyyy")));
            //}

        }
    }
}